﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Gav.Data;

namespace Infovizprojekt
{
    public class DataHandler : BaseHandler
    {
        public ExcelDataProvider RawDataProvider { get; set; }

        public NaNTransformer AllDataDataCubeProvider { get; set; }

        public SliceTransformer MainDataCubeProvider { get; set; }
        public YearVarTransformer YearDataCubeProvider { get; set; }
        public KMeansDataTransformer KMeansDataCubeProvider { get; set; }

        public const int StartYear = 1990;
        public const int EndYear = 2005;

        public DataHandler(MainWindow mainWindow) : base(mainWindow)
        {
            init();
        }

        public void init()
        {
            RawDataProvider = new ExcelDataProvider();

            AllDataDataCubeProvider = new NaNTransformer();
            MainDataCubeProvider = new SliceTransformer();
            YearDataCubeProvider = new YearVarTransformer();

            //read data from excel file
            RawDataProvider.HasIDColumn = true;
            RawDataProvider.Load(@"..\..\..\data\data.xls");

            AllDataDataCubeProvider.Input = RawDataProvider;
            AllDataDataCubeProvider.CommitChanges();

            YearDataCubeProvider.Input = AllDataDataCubeProvider;
            MainDataCubeProvider.Input = AllDataDataCubeProvider;

            KMeansDataCubeProvider = new KMeansDataTransformer();
            KMeansDataCubeProvider.Input = MainDataCubeProvider;
        }

        public List<string> getColumnHeaders()
        {
            return RawDataProvider.GetColumnHeaders();
        }

        public List<string> getYearsAsList()
        {
            List<string> yearList = new List<string>();

            for (int i = StartYear; i <= EndYear; i++)
            {
                yearList.Add(i.ToString());
            }

            return yearList;
        }

        public string getValueFromDataCube(int x, int y, int z)
        {
            String str;

            str = AllDataDataCubeProvider.GetDataCube().DataArray[x, y, z].ToString();

            return str;
        }

    }
}